package com.nobuyme.box.toy;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.nobuyme.box.MainActivity;
import com.nobuyme.box.R;
import com.nobuyme.box.account.Account;
import com.nobuyme.box.account.AccountManager;
import com.nobuyme.box.toy.manage.PutGoodsActivity;
import com.nobuyme.box.xunfei.XunFeiSpeech;
import com.pachong.android.baseuicomponent.activity.BaseActivity;

import butterknife.Bind;
import butterknife.OnClick;

public class ReturnSuccessActivity extends BaseActivity {

    private final static String POSITION = "openPosition";
    @Bind(R.id.tv_return_num)
    TextView mTvReturnNum;
    private int position;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        position = getIntent().getExtras().getInt(POSITION);
        hideToolbar();
        initData();
    }

    private void initData() {
        mTvReturnNum.setText(position+"号储物格已打开");
        Account acc = AccountManager.getCurrentAccount();
        PutGoodsActivity.openLattice(acc.getId(),acc.getPolling_one(),acc.getPolling_two(),acc.getPolling_three(),acc.getPolling_four(),position);
        //语音
        try {
            XunFeiSpeech xunFeiSpeech = new XunFeiSpeech(this);
            xunFeiSpeech.speak("12", position + "号储物格已打开,请放入玩具", new XunFeiSpeech.OnCompleteListener() {
                @Override
                public void onComplete() {
//                    EasyToast.showToast(PutGoodsActivity.this,"柜门已打开");
                }
            });
        } catch (NullPointerException e) {
        }
    }

    public static void start(Context context, int openPosition) {
        Intent intent = new Intent(context, ReturnSuccessActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
        intent.putExtra(POSITION,openPosition);
        context.startActivity(intent);
    }


    @Override
    public View createDataView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.activity_return_success, null);
    }

    @OnClick(R.id.btn_return_back)
    public void onViewClicked() {
        try {
            XunFeiSpeech xunFeiSpeech = new XunFeiSpeech(this);
            xunFeiSpeech.speak("12", "归还成功，请关闭柜门", new XunFeiSpeech.OnCompleteListener() {
                @Override
                public void onComplete() {
//                    EasyToast.showToast(PutGoodsActivity.this,"柜门已打开");
                }
            });
        } catch (NullPointerException e) {

        }
        MainActivity.start(ReturnSuccessActivity.this);
            finish();

    }
}
